home *** CD-ROM | disk | FTP | other *** search
/ Light ROM 1 / LIGHT-ROM 1 (Amiga Library Services)(1994).iso / ffdisks / d882.lha / GALer / GALer_english / Source / GALerSrcE.lha / GALerTest.c < prev    next >
C/C++ Source or Header  |  1993-06-07  |  11KB  |  536 lines

  1. /****************************************************************/
  2. /*                                */
  3. /* Testprogramm für GAL-Brenner                    */
  4. /*                                */
  5. /* Soft- and Hardware  copyright (c)1991            */
  6. /*     by Christian Habermann                    */
  7. /*        Asamstr. 17                        */
  8. /*        8050 Freising (W-Germany)                */
  9. /*                                */
  10. /*  cc -z4000 GALerTest.c                    */
  11. /*  as -n -c -d port.asm                    */
  12. /*  ln GALerTest.o port.o -lc                    */
  13. /*                                */
  14. /****************************************************************/
  15.  
  16.  
  17.  
  18. #include <exec/memory.h>
  19. #include <exec/ports.h>
  20. #include <exec/types.h>
  21. #include <intuition/intuition.h>
  22. #include <functions.h>
  23.  
  24. #include "GALer.h"
  25.  
  26.  
  27. #define     YPOS    30
  28.  
  29.  
  30. void Clear();
  31. void Print();
  32. void WaitForAction();
  33.  
  34.  
  35.  
  36. struct    MsgPort        *timeport;
  37. struct    timerequest    *timereq;
  38. struct    IntuitionBase    *IntuitionBase;
  39. struct    GfxBase        *GfxBase;
  40. struct    IntuiMessage    *message;
  41. struct    Window        *window;
  42. struct    RastPort    *rp;
  43. struct    TextFont    *txtfont;
  44. struct    TextAttr    txtattr;
  45.  
  46.  
  47. SHORT BorderVectors1a[] = { 0,15,73,15,73,0 };
  48. SHORT BorderVectors1b[] = { 0,15,0,0,73,0 };
  49.  
  50. struct Border Border1b    = { -1,-1,2,0,JAM1,3,BorderVectors1b,NULL };
  51. struct Border Border1a    = { -1,-1,1,0,JAM1,3,BorderVectors1a,&Border1b };
  52.  
  53.  
  54.  
  55. struct IntuiText GadIText3 = { 1,0,JAM2,4,4,&txtattr,
  56.                    (UBYTE *)"  EXIT  ",NULL };
  57.  
  58. struct IntuiText GadIText2 = { 1,0,JAM2,12,4,&txtattr,
  59.                    (UBYTE *)"Cancel",NULL };
  60.  
  61. struct IntuiText GadIText1 = { 1,0,JAM2,4,4,&txtattr,
  62.                    (UBYTE *)"Continue",NULL };
  63.  
  64.  
  65.  
  66. struct Gadget CancelGad = { NULL, 530, 180, 72, 14,
  67.                 NULL,
  68.                 RELVERIFY,
  69.                 BOOLGADGET+REQGADGET,
  70.                 (APTR)&Border1a,NULL,
  71.                 &GadIText2,NULL,NULL,1,NULL };
  72.  
  73. struct Gadget ContGad   = { &CancelGad, 40, 180, 72, 14,
  74.                 NULL,
  75.                 RELVERIFY,
  76.                 BOOLGADGET+REQGADGET,
  77.                 (APTR)&Border1a,NULL,
  78.                 &GadIText1,NULL,NULL,0,NULL };
  79.  
  80.  
  81.  
  82.  
  83. struct NewWindow MyWin =  { 0,0,640,200,
  84.                 0,1,
  85.                 CLOSEWINDOW|GADGETUP,
  86.                 ACTIVATE|WINDOWCLOSE|WINDOWDRAG|WINDOWDEPTH,
  87.                 &ContGad,NULL,
  88.                 (UBYTE *)"GALerTest  (c) 1993 by Christian Habermann",
  89.                 NULL,NULL,
  90.                 0,0,0,0,
  91.                 WBENCHSCREEN
  92.               };
  93.  
  94.  
  95.  
  96.  
  97. int    prog_volt = 0;        /*Dummy für das Modul "Port"*/
  98. int    ytxt = YPOS;
  99.  
  100. main()
  101. {
  102. int errorIC6, errorIC7;
  103. int n;
  104.  
  105.  
  106.  openstuff();
  107.  
  108.  if (GetTimer()) {                /*Timer holen*/
  109.    puts("kann Timer nicht finden\n");
  110.    exit(FALSE);    
  111.   }
  112.  
  113.  
  114.  rp = window -> RPort;
  115.  
  116.  SetAPen(rp, 1L);
  117.  SetFont(rp, txtfont);            /*Font für Textausgabe*/
  118.  
  119.  
  120.  
  121.  
  122.  InitParPort();                /*Datenrichtungsregister der CIAs*/
  123.  
  124.  InitGALer();
  125.  
  126.  Print("This is a program for testing the hardware V1.2 of the GALer project.");
  127.  Print("You need this program to adjust the trimpots R40-44 too.");
  128.  Print("IMPORTANT: There must be no GAL in the Textool socket now!");
  129.  Print("");
  130.  Print("If the hardware works not as the test program demands, then");
  131.  Print("you should cancel 'GALerTest' immediately and try to remove the");
  132.  Print("bug in your hardware.");
  133.  Print("");
  134.  Print("Please select the 'Continue' gadget to start the test.");
  135.  WaitForAction(0);
  136.  
  137.  
  138.  Clear();
  139.  Print("Now the LED should be off and all pins of the Textool socket should");
  140.  Print("be set at LOW level (about 0 volt).");
  141.  Print("");
  142.  Print("Please select 'Continue'!");
  143.  EnableOutput();
  144.  WriteByte(0x00,IC3);
  145.  WriteByte(0x00,IC4);
  146.  WriteByte(0x00,IC5);
  147.  WaitForAction(0);
  148.  
  149.  
  150.  Clear();
  151.  Print("Now the LED should be on.");
  152.  Print("");
  153.  Print("Please select 'Continue'!");
  154.  LED(ON);
  155.  WaitForAction(0);
  156.  
  157.  
  158.  Clear();
  159.  Print("Now the LED should be off again.");
  160.  Print("");
  161.  Print("Please select 'Continue'!");
  162.  LED(OFF);
  163.  WaitForAction(0);
  164.  
  165.  
  166.  Clear();
  167.  Print("At pin 24 of the Textool socket should be a HIGH level (about 5 volt).");
  168.  Print("");
  169.  Print("Please select 'Continue'!");
  170.  SetGAL(GAL20V8);
  171.  EnableVcc();
  172.  WaitForAction(0);
  173.  
  174.  
  175.  Clear();
  176.  Print("At pin 22 of the Textool socket should be a HIGH level too.");
  177.  Print("");
  178.  Print("Please select 'Continue'!");
  179.  DisableVcc();
  180.  SetGAL(GAL16V8);
  181.  EnableVcc();
  182.  WaitForAction(0);
  183.  
  184.  
  185.  Clear();
  186.  Print("At all pins should be a HIGH level with exception of pin 12.");
  187.  Print("Pin 12 is GND.");
  188.  Print("");
  189.  Print("Please select 'Continue'!");
  190.  InitGALer();
  191.  EnableOutput();
  192.  WriteByte(0xff,IC3);
  193.  WriteByte(0xff,IC4);
  194.  WriteByte(0xff,IC5);
  195.  WaitForAction(0);
  196.  
  197.  
  198.  Clear();
  199.  Print("At pins 1, 3, 5, 7, 9, 12, 14, 16, 18, 20, 22, 24 should be a HIGH level.");
  200.  Print("All other pins should be LOW.");
  201.  Print("");
  202.  Print("Please select 'Continue'!");
  203.  SetGAL(GAL20V8);
  204.  EnableVcc();
  205.  WriteByte(0x55,IC3);
  206.  WriteByte(0x55,IC4);
  207.  WriteByte(0x55,IC5);
  208.  WaitForAction(0);
  209.  
  210.  
  211.  Clear();
  212.  Print("Now at pins 2, 4, 6, 8, 10, 13, 15, 17, 19, 21, 23 should be a HIGH level.");
  213.  Print("All other pins should be LOW.");
  214.  Print("");
  215.  Print("Please select 'Continue'!");
  216.  DisableVcc();
  217.  WriteByte(0xaa,IC3);
  218.  WriteByte(0xaa,IC4);
  219.  WriteByte(0xaa,IC5);
  220.  WaitForAction(0);
  221.  
  222.  
  223.  DisableVcc();
  224.  InitGALer();
  225.  EnableOutput();
  226.  VeditOn();
  227.  
  228.  
  229.  Clear();
  230.  Print("***************************************************************************");
  231.  Print("Now you have to adjust the trimpots R40-R44.");
  232.  Print("If this does not work, check IC 9, IC 10, T3, T4.");
  233.  
  234.  Print("");
  235.  Print("Use trimpot R40 to adjust the voltage at pin 2 to exactly 16.5V.");
  236.  Print("Please select 'Continue'!");
  237.  SetVolt(0);
  238.  SetGAL(GAL20V8);
  239.  EnableVEdit();
  240.  WaitForAction(0);
  241.  
  242.  Print("");
  243.  Print("Use trimpot R41 to adjust the voltage at pin 2 to exactly 15.75V.");
  244.  Print("Please select 'Continue'!");
  245.  SetVolt(1);
  246.  WaitForAction(0);
  247.  
  248.  Print("");
  249.  Print("Use trimpot R42 to adjust the voltage at pin 2 to exactly 14.5V.");
  250.  Print("Please select 'Continue'!");
  251.  SetVolt(2);
  252.  WaitForAction(0);
  253.  
  254.  Print("");
  255.  Print("Use trimpot R43 to adjust the voltage at pin 2 to exactly 14.0V.");
  256.  Print("Please select 'Continue'!");
  257.  SetVolt(3);
  258.  WaitForAction(0);
  259.  
  260.  Print("");
  261.  Print("Use trimpot R44 to adjust the voltage at pin 2 to exactly 12.0V.");
  262.  Print("Please select 'Continue'!");
  263.  SetVolt(4);
  264.  WaitForAction(0);
  265.  
  266.  Print("");
  267.  Print("O.K., now all voltages are adjusted. Let me do some other tests.");
  268.  Print("Please select 'Continue'!");
  269.  Print("***************************************************************************");
  270.  WaitForAction(0);
  271.  Clear();
  272.  
  273.  Print("Now at pin 4 should be a voltage of 12.0V and pin 2 should be");
  274.  Print("at LOW level. If this does not work, check T1, T2.");
  275.  Print("");
  276.  Print("Please select 'Continue'!");
  277.  DisableVEdit();
  278.  SetGAL(GAL16V8);
  279.  EnableVEdit();
  280.  WaitForAction(0);
  281.  Clear();
  282.  
  283.  
  284.  
  285.  
  286.             /*ab hier wird überprüft, ob das Auslesen der*/
  287.             /*Ausgangspegel des GALs funktioniert (IC6a, IC7)*/
  288.  Print("Now I'm trying to read pins 14-22 of the Textool socket...");
  289.  SetGAL(GAL20V8);
  290.  InitGALer();
  291.  EnableVcc();
  292.  EnableOutput();
  293.             /*IC6a testen*/
  294.  errorIC6 = errorIC7 = 0;
  295.  WriteByte(0x40,IC3);
  296.  if (!ReadByte(IC6))
  297.    errorIC6 = 1;
  298.  
  299.  WriteByte(0x00,IC3);
  300.  if (ReadByte(IC6))
  301.    errorIC6 = 1;
  302.             /*IC7 testen*/
  303.  WriteByte(0x00,IC5);
  304.  if (ReadByte(IC7))
  305.    errorIC7 = 1;
  306.  
  307.  WriteByte(0x2A,IC3);
  308.  WriteByte(0x20,IC5);
  309.  if (ReadByte(IC7) != 0xAA)
  310.    errorIC7 = 1;
  311.  
  312.  WriteByte(0x15,IC3);
  313.  WriteByte(0x10,IC5);
  314.  if (ReadByte(IC7) != 0x55)
  315.    errorIC7 = 1;
  316.  
  317.  DisableVcc();
  318.  DisableOutput(); 
  319.  
  320.  if (errorIC6 || errorIC7) {
  321.    Print("");
  322.    Print(" ERROR!!!");
  323.    Print("   There must be an error at the BUSY line, R27, IC8, IC6a, IC6b, IC7");
  324.    Print("   or R13. Please check this components.");
  325.    Print("");
  326.    Print(" Description of error:");
  327.    if (errorIC6 && !errorIC7) {
  328.      Print("  I can't read pin 22 through the BUSY line of the parallel port.");
  329.    }
  330.  
  331.    if (!errorIC6 && errorIC7) {
  332.      Print("  I can't read pins 14-21 through the BUSY line of the parallel port.");
  333.    }
  334.  
  335.    if (errorIC6 && errorIC7) {
  336.      Print("  I can't read pins 14-21 and pin 22 through the BUSY line of the");
  337.      Print("  parallel port.");
  338.    }
  339.  
  340.  }
  341.  else {
  342.  
  343.    Print("O.K., no error found (you have a lot going for you).");
  344.    Print("");
  345.    Print("If you found no errors and if you have adjusted all voltages");
  346.    Print("(12V, 14V, 14.5V, 15.75V and 16.5V), GALer works fine.");
  347.    Print("");
  348.    Print("Now you can read/program GALs by using the software called GALer.");
  349.  
  350.  }
  351.  
  352.  
  353.  CancelGad.GadgetText = &GadIText3;
  354.  OffGadget(&ContGad, window, NULL);
  355.  RefreshGList(&ContGad, window, NULL);
  356.  
  357.  WaitForAction(0);
  358.  
  359.  
  360.  RestoreParPort();
  361.  
  362.  FreeTimer();
  363.  
  364.  closestuff();
  365. }
  366.  
  367.  
  368.  
  369.  
  370.  
  371.  
  372. GetTimer()                /*Timer holen*/
  373. {
  374.  
  375.  timeport = CreatePort(0L,0L);
  376.  if (timeport == NULL)
  377.    return(-1);
  378.  
  379.  timereq=(struct timerequest *)AllocMem(
  380.             (long)sizeof(struct timerequest),MEMF_PUBLIC);
  381.  if (timereq == NULL) {
  382.    DeletePort(timeport);
  383.    return(-1);
  384.   }
  385.  
  386.  timereq->tr_node.io_Message.mn_Node.ln_Type=NT_MESSAGE;
  387.  timereq->tr_node.io_Message.mn_Node.ln_Pri=0;
  388.  timereq->tr_node.io_Message.mn_ReplyPort=timeport;
  389.  
  390.  if (OpenDevice(TIMERNAME,UNIT_MICROHZ,timereq,0L)) {
  391.    FreeMem(&timereq,(long)sizeof(struct timerequest));
  392.    DeletePort(timeport);
  393.    return(-1);
  394.   }
  395.  
  396.  return(0);
  397. }
  398.  
  399.  
  400.  
  401. void FreeTimer()            /*Timer wieder freigeben*/
  402. {
  403.  CloseDevice(timereq);
  404.  FreeMem(timereq,(long)sizeof(struct timerequest));
  405.  DeletePort(timeport);
  406. }
  407.  
  408.  
  409.  
  410. /*micro: microsec. to wait
  411.   secs: seconds to wait
  412. */
  413. void WaitForTimer(micro)
  414. ULONG micro;
  415. {
  416.  timereq->tr_node.io_Command=TR_ADDREQUEST;
  417.  timereq->tr_time.tv_secs=0;
  418.  timereq->tr_time.tv_micro=micro;
  419.  DoIO(timereq);
  420. }
  421.  
  422.  
  423.  
  424.  
  425. void Clear()
  426. {
  427.  ytxt = YPOS;
  428.  SetAPen(rp, 0L);
  429.  RectFill(rp, 10L, 22L, 630L, 170L);
  430.  SetAPen(rp, 1L);
  431. }
  432.  
  433.  
  434.  
  435. void Print(text)
  436. UBYTE    *text;
  437. {
  438.  
  439.  if (ytxt < 160)
  440.    ytxt += 10;
  441.  else
  442.    ScrollRaster(rp,0L,10L,10L,22L,630L,170L);
  443.  
  444.  Move(rp,20L,(long)ytxt);
  445.  Text(rp,text,(long)strlen(text));
  446. }
  447.  
  448.  
  449.  
  450.  
  451. /* wartet auf das Anklicken eines Gadgets
  452. */
  453. void WaitForAction()
  454. {
  455. ULONG    class;
  456. USHORT    code,gadID;
  457.  
  458.  for(;;) {
  459.    Wait(1L<<window->UserPort->mp_SigBit);
  460.    if (message=(struct IntuiMessage *)GetMsg(window->UserPort)) {
  461.      class = message -> Class;
  462.      code  = message -> Code;
  463.      if (class == GADGETUP)
  464.        gadID=((struct Gadget *)message->IAddress)->GadgetID;
  465.      ReplyMsg(message);
  466.  
  467.      switch(class) {
  468.     case CLOSEWINDOW: closestuff();        /*Programm fluchtartig*/
  469.               FreeTimer();        /*verlassen*/
  470.               RestoreParPort();
  471.               exit(0);
  472.               break;
  473.  
  474.     case GADGETUP:    if (!gadID)
  475.                 return;                
  476.               else {        /*Abbruch angeklickt*/
  477.                 closestuff();
  478.                 FreeTimer();
  479.                 RestoreParPort();
  480.                 exit (0);
  481.               }
  482.               break;
  483.      }
  484.    }
  485.  }
  486. }
  487.  
  488.  
  489.  
  490.  
  491.  
  492. closestuff()
  493. {
  494.   if (window)  CloseWindow(window);
  495.   if (GfxBase) CloseLibrary(GfxBase);
  496.   if (IntuitionBase) CloseLibrary (IntuitionBase);
  497. }
  498.  
  499.  
  500. openstuff()
  501. {
  502.  if ((IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",0L)) == NULL) {
  503.    puts ("kann intuition.library nicht öffnen");
  504.    exit(FALSE);
  505.  }
  506.  
  507.  if ((GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",0L)) == NULL) {
  508.    puts ("kann graphics.library nicht öffnen");
  509.    closestuff();
  510.    exit(FALSE);
  511.  }
  512.  
  513.  
  514.  txtattr.ta_Name  = (STRPTR)"topaz.font";        /*Font holen*/
  515.  txtattr.ta_YSize = 8;
  516.  txtattr.ta_Style = 0;
  517.  txtattr.ta_Flags = 0;
  518.  
  519.  if (!(txtfont = (struct TextFont *)OpenFont(&txtattr))) {
  520.    puts("kann topaz.font 8 nicht finden");
  521.    closestuff();
  522.    exit(FALSE);
  523.  }
  524.  
  525.  
  526.  if ((window = (struct Window *)OpenWindow(&MyWin)) == NULL) {
  527.    puts ("kann Fenster nicht öffnen");
  528.    closestuff();
  529.    exit(FALSE);
  530.  }
  531. }
  532.  
  533.  
  534.  
  535.  
  536.